#include "profile.h"
#include "ui_profile.h"
#include "../../models/usermodel.h"

//@todo 样式，无边框，可拖动，坐上加个关闭
Profile::Profile(QWidget *parent)//parent参数表示父类，如果不传表示该部件没有父类
    : QWidget(parent)
    , ui(new Ui::Profile)
{
    ui->setupUi(this);

    this->styleSelf();
}

void Profile::styleSelf(){

    this->setStyleSheet("background:transparent;background-color:#f7f7f7;");
    //this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground );

    ui->closeButton->setStyleSheet(LEFT_CLOSE_BUTTON_STYLE);
}

void Profile::setUserProfile(responseUserInfo userInfo){
//    QString avatarUrl = ":/icon/source/profile/avatar80.png";
    QString nickname = userInfo.username;
    QString avatar = userInfo.avatar;

    ui->avatarLabel->setStyleSheet("border-image:url(:" + avatar + ")");
    ui->nicknameLabel->setText(nickname);
    ui->nicknameLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    ui->avatarLabel->raise();
    ui->groupBox->lower();
    ui->avatarLabel->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint);
}

void Profile::on_closeButton_clicked()
{
    this->close();
}
